import { auth } from "@clerk/nextjs/server";
import { clerkClient } from "@clerk/nextjs/server";

/**
 * 获取当前用户的Clerk认证信息
 */
export function getAuth() {
  return auth();
}

/**
 * 获取当前用户ID
 */
export function getCurrentUserId(): string | null {
  const { userId } = getAuth();
  return userId;
}

/**
 * 获取当前用户的邮箱
 */
export async function getCurrentUserEmail(): Promise<string | null> {
  const userId = getCurrentUserId();
  if (!userId) return null;

  const user = await clerkClient.users.getUser(userId);
  return user.emailAddresses[0]?.emailAddress || null;
}

/**
 * 获取当前用户信息
 */
export async function getCurrentUser() {
  const userId = getCurrentUserId();
  if (!userId) return null;

  return await clerkClient.users.getUser(userId);
} 